package com.GUI.CustomControls;

import com.GUI.EmployeeTableObject;
import com.GUI.Popup;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableView;

/**
 *
 * @author Prezes
 */
public class EditButtonTableCell extends TableCell<EmployeeTableObject, String> {
    
        final private Button cellButton = new Button("edytuj");
         
        public EditButtonTableCell()
        {
            cellButton.setOnAction(new EventHandler<ActionEvent>(){
 
                @Override
                public void handle(ActionEvent t) {
                    EmployeeTableObject eto = getTableView().getItems().get(getTableRow().getIndex());
                    
                    System.out.println("Edycja pracownika: " + eto.getName() + " " + eto.getSurname());
                    System.out.println(eto.getId());
                    
                    Popup popup = new Popup();
              
                    try {
                        popup.createPopupEdit(eto.getId());
                    } catch (Exception ex) {
                        popup.createPopupInfo("Wystąpił problem! Skontaktuj się z programist(k)ą!");
                    }
                }
            });
        }
 
        //Display button if the row is not empty
        @Override
        protected void updateItem(String t, boolean empty) 
        {
            super.updateItem(t, empty);
            if(!empty)
            {
                setGraphic(cellButton);
            }
        }
    }
